package core;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class ProductGroupTests
{
	private RootStorageUnit root;
	private Amount amount;
	private Amount amount2;
	private StorageUnit unit1;
	private StorageUnit unit2;
	private ProductGroup group1;
	private ProductGroup group2;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
		
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
		
	}

	@Before
	public void setUp() throws Exception
	{
		root = RootStorageUnit.getInstance();
		amount = new Amount(Unit.count, 0);

		amount2 = new Amount(Unit.gallons, 5);
		unit1 = new StorageUnit("storage");
		unit2 = new StorageUnit("storage2");
		group1 = new ProductGroup("group1",amount, unit1);
		group2 = new ProductGroup("group2",amount2, unit2);
		
	}

	@After
	public void tearDown() throws Exception
	{
		
	}
	
	@Test
	public void ProductGroupTest()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		
		assertTrue(group1.getName().compareTo("group1")==0);
		assertTrue(group1.getParentContainer().equals(unit1));
		assertTrue(group1.getThreeMonthSupplyAmount().equals(amount));
		assertTrue(group1.getProductGroups()!= null);
	}
	
	@Test
	public void set_and_getParentContainerTests()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		
		assertTrue(group1.getParentContainer().equals(unit1));
		group1.setParentContainer(unit2);
		assertFalse(group1.getParentContainer().equals(unit1));
		assertTrue(group1.getParentContainer().equals(unit2));
	}
	
	@Test
	public void set_and_getThreeMonthSupplyTests()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		
		assertTrue(group1.getThreeMonthSupplyAmount().equals(amount));
		group1.setThreeMonthSupply(amount2);
		assertFalse(group1.getThreeMonthSupplyAmount().equals(amount));
		assertTrue(group1.getThreeMonthSupplyAmount().equals(amount2));
	}
	
	@Test
	public void getContainerTypeTest()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		
		assertTrue(group1.getContainerType()== ContainerType.PRODUCT_GROUP);
		assertFalse(group1.getContainerType()== ContainerType.STORAGE_UNIT);
	}
	
	@Test
	public void editProductGroupTest()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		Amount amount = new Amount(Unit.count, 0);
		Amount amount2 = new Amount(Unit.gallons, 5);
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		ProductGroup group2 = new ProductGroup("group2",amount2, unit2);
		
		group1.editProductGroup(group2);
		
		assertTrue(group1.getName() == group2.getName());
		assertTrue(group1.getParentContainer() == group2.getParentContainer());
		assertTrue(group1.getThreeMonthSupplyAmount() == group2.getThreeMonthSupplyAmount());
	}
	

}
